package com.loren.oauth.config;

import com.loren.oauth.handler.CustomAccessDeniedHandler;
import com.loren.oauth.handler.CustomAuthenticationEntryPoint;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;

@Configuration
@AllArgsConstructor
@EnableResourceServer
public class OAuth2ResourceConfig extends ResourceServerConfigurerAdapter {

	private final CustomAccessDeniedHandler customAccessDeniedHandler;

	private final CustomAuthenticationEntryPoint customAuthenticationEntryPoint;

	@Override
	public void configure(ResourceServerSecurityConfigurer resources) {
		resources
				.accessDeniedHandler(this.customAccessDeniedHandler)
				.authenticationEntryPoint(this.customAuthenticationEntryPoint);
	}

}
